import { client } from '../../request/index.js'
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog'

Page({
  data: {
    imgIp: getApp().globalData.imgIp,
    cooperativepurpose: '',
    email: '',
    linkMan: '',
    address: '',
    telephone: '',
    companyName: '',
    description: '',
    size: { maxHeight: 500, minHeight: 100 },
  },

  onLoad: function (options) {
    this.setData({
      cooperativepurpose: '',
      email: '',
      linkMan: '',
      address: '',
      telephone: '',
      companyName: '',
      description: '',
    })
  },
  //确认提交
  handleClick: function (v) {
    var that = this
    var companyName = v.detail.value.companyName
    var description = v.detail.value.description
    var linkMan = v.detail.value.linkMan
    var telephone = that.validateNumber(v.detail.value.telephone)
    var email = v.detail.value.email
    var address = v.detail.value.address
    var cooperativepurpose = v.detail.value.cooperativepurpose
    if (
      companyName == '' ||
      description == '' ||
      linkMan == '' ||
      telephone == '' ||
      email == '' ||
      address == '' ||
      cooperativepurpose == ''
    ) {
      Dialog.alert({
        title: '提示',
        message: '请输入完整信息！',
      })
    } else {
      this.bussinessCooperation(v)
    }
  },
  //正则电话
  validateNumber(val) {
    return val.replace(/\D/g, '')
  },
  //商务合作
  async bussinessCooperation(v) {
    var companyName = v.detail.value.companyName
    var description = v.detail.value.description
    var linkMan = v.detail.value.linkMan
    var telephone = this.validateNumber(v.detail.value.telephone)
    var email = v.detail.value.email
    var address = v.detail.value.address
    var cooperativepurpose = v.detail.value.cooperativepurpose
    const getData = await client({
      url: '/SettledCompany/insert',
      method: 'POST',
      data: {
        companyName: companyName,
        description: description,
        cooperativepurpose: cooperativepurpose,
        email: email,
        address: address,
        linkMan: linkMan,
        telephone: telephone,
      },
    })
    console.log('企业信息', getData)
    this.onLoad()
    wx.showToast({
      title: '提交成功',
      icon: 'success',
      duration: 2000,
    })
  },
})
